package com.springboot.tools.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;


@WebFilter(filterName = "AsyncFilter", value = {"/servlet/AsynServlet"},
        dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.ASYNC},
        asyncSupported = true)
public class AsyncFilter implements Filter {

    @Override
    public void destroy() {
        System.out.println("destroy-----AsyncFilter");
        System.out.println();
        System.out.println();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) {
        System.out.println("doFilter--start---AsyncFilter");
        try {
            chain.doFilter(request, response);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ServletException e) {
            e.printStackTrace();
        }
        System.out.println("doFilter--stop---AsyncFilter");
    }

    @Override
    public void init(FilterConfig filterConfig) {
        System.out.println("init--init---AsyncFilter");
    }

}
